package top.lyc829.mymusic.adapter.multi.comment

import android.view.LayoutInflater
import android.view.ViewGroup
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.binder.QuickViewBindingItemBinder
import top.lyc829.mymusic.databinding.ItemCommentBinding
import top.lyc829.mymusic.ext.getCorrespondString
import top.lyc829.mymusic.ext.load
import top.lyc829.mymusic.model.bean.Comment
import java.text.DateFormat

/**
 * @Author lyc
 * @create 2021-09-02 10:22
 */
class CommentBinder: QuickViewBindingItemBinder<Comment, ItemCommentBinding>() {
    override fun convert(holder: BinderVBHolder<ItemCommentBinding>, data: Comment) {
        holder.viewBinding.run {
            commentItemUsername.text = data.user.nickname
            commentItemTime.text = TimeUtils.millis2String(data.time, DateFormat.getDateInstance())
            commentItemText.text = data.content
            commentItemAvatar.load(data.user.avatarUrl)
            commentItemLikeNums.text = data.likedCount.getCorrespondString
            commentItemGoReplay.text = "${data.likedCount}条回复 >"
        }
    }

    override fun onCreateViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemCommentBinding {
        return ItemCommentBinding.inflate(layoutInflater, parent, false)
    }
}